package com.yfp.operation.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yfp.operation.domain.ActivitySignInsClients;
import com.yfp.operation.domain.dto.ActivitySignInsClientsCountDTO;
import com.yfp.operation.domain.dto.ActivitySignInsSearchParticipationReq2DTO;
import com.yfp.operation.domain.vo.ActivitySignInsSearchParticipationReqVO;
import com.yfp.operation.mapper.ActivitySignInsClientsMapper;
import com.yfp.operation.service.ActivitySignInsClientsService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 *
 * @description 针对表【activity_sign_ins_clients(打卡管理-参与用户表)】的数据库操作Service实现
 * @createDate 2025-01-02 10:22:14
 */
@Service
public class ActivitySignInsClientsServiceImpl extends ServiceImpl<ActivitySignInsClientsMapper, ActivitySignInsClients> implements ActivitySignInsClientsService {

    @Resource
    private ActivitySignInsClientsMapper activitySignInsClientsMapper;

    @Override
    public HashMap<Long, Long> countByActivitySignInsIds(List<Long> activitySignInsIds) {
        if (CollUtil.isEmpty(activitySignInsIds)){
            return new HashMap<>();
        }

        List<ActivitySignInsClientsCountDTO> activitySignInsClientsCountDTOS = activitySignInsClientsMapper.countByActivitySignInsIds(activitySignInsIds);
        return activitySignInsClientsCountDTOS.stream().collect(HashMap::new, (m, v) -> m.put(v.getActivitySignInsId(), v.getUserCount()), HashMap::putAll);
    }

    @Override
    public List<ActivitySignInsSearchParticipationReqVO> searchParticipationList(ActivitySignInsSearchParticipationReq2DTO searchReqDTO) {
        return activitySignInsClientsMapper.searchParticipationList(searchReqDTO);
    }

    @Override
    public Boolean joined(String clientId, Long activitySignInsId) {
        ActivitySignInsClients activitySignInsClients = new ActivitySignInsClients();
        activitySignInsClients.setActivitySignInsId(activitySignInsId);
        activitySignInsClients.setClientId(clientId);

        List<ActivitySignInsClients> activitySignInsClientsList = activitySignInsClientsMapper.selectByReq(activitySignInsClients);
        return CollUtil.isNotEmpty(activitySignInsClientsList);
    }

    @Override
    public void incrementCount(String clientId, Long activitySignInsId) {
        activitySignInsClientsMapper.incrementCount(clientId, activitySignInsId);
    }

    @Override
    public Long currentCount(String clientId, Long activitySignInsId) {
        return activitySignInsClientsMapper.selectCurrentCount(clientId, activitySignInsId);
    }
}




